package com.sangeng.runner;

import com.sangeng.domain.entity.Article;
import com.sangeng.mapper.ArticleMapper;
import com.sangeng.service.ArticleService;
import com.sangeng.utils.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class testRunner implements CommandLineRunner {
    @Autowired
    private RedisCache redisCache;
    @Autowired
    private ArticleService articleService;
    @Override
    public void run(String... args) throws Exception {
//        setViewCountToRedis();
        System.out.println("runner");
    }

    private void setViewCountToRedis() {
        List<Article> list = articleService.list();
        list.forEach(item->{
            System.out.println(item.getId());
            redisCache.setCacheObject("articleViewCount:"+item.getId(),item.getViewCount());
        });
    }
}
